package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.pojo.Menu;
import com.itheima.service.MenuService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @PackageName: com.itheima.controller
 * @ClassName: MenuController
 * @Author: AdamMing
 * @Date: 2020/3/19 15:29
 * @Description: 菜单相关服务controller
 */
@RestController
@RequestMapping("/menu")
public class MenuController {

    @Reference
    private MenuService menuService;
    @RequestMapping("/findAll")
    public Result findAll(){
        try {
            List<Menu> data = menuService.findAll();
            return new Result(true, MessageConstant.QUERY_MENU_SUCCESS,data);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,MessageConstant.QUERY_MENU_FALL);
        }
    }

    @RequestMapping("/findMenuIdsByRoleId")
    public Result findMenuIdsByRoleId(Integer roleId){
        try {
            List<Integer> data = menuService.findMenuIdsByRoleId(roleId);
            return new Result(true, MessageConstant.QUERY_MENU_SUCCESS,data);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,MessageConstant.QUERY_MENU_FALL);
        }
    }
}
